home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
web
/
fweb
/
fweb-1.40
/
manual
/
f_to_web.web
< prev
next >
Wrap
Text File
|
1993-10-29
|
3KB
|
102 lines
@z --- f_to_web.web ---
This file is part of FWEB. It and its various pieces of processed output are
included into the user manual fwebman.tex.
Author: J. A. Krommes
Version: 1.23
Date: April 1, 1992
@x-----------------------------------------------------------------------------
@n/ @% Set the language to Fortran, and allow short comments.
\def\title{--- F\_TO\_WEB ---}
@* INTRODUCTION. This demo shows you how to convert the file
\.{f\_to\_web.src} (look at that file with your editor now) into a valid
\.{FWEB} file, namely this file \.{f\_to\_web.web}. Each subroutine should
be placed into a separate module, begun with~`\.{@@*}' or~`\.{@@\ }'. After
those symbols, you should explain what the subroutine does, using \TeX\ in
all its glory. Then follows the code, introduced by~`\.{@@a}' or
`\.{@@<...@@>=}'. Code sections should be short---about 12 lines, according
to Knuth. If they're too long, break them up into named fragments that are
explained separately. For new code, comments should be C-style---namely,
``\.{/*...*/}'' or ``\.{//...}''. (In order to use the latter form, you
must use the command-line option~`\.{-n/}', and then you must use the
symbol~`\.{\\/}' for concatenation.)
Before proceeding, let us note that standard Fortran is {\it not}
recommended for new code. Use the Ratfor mode instead. Standard Fortran
mode is intended primarily to support conversion of existing code.
Notice how forward references to named modules and function names are
handled in the woven output.
@a
program main
@<Common blocks@>
/* Initialize values. Long comments should be done in standard
C style and may be continued across lines. */
x = -3.14159e-11
i = 1
call see // Print results. (Short comments can be done like this.)
end
@ Code fragments can be defined anywhere, even after they are used.
@f @<Com...@> common /* Use a format statement to tell \.{WEAVE} how to handle
this module name. */
@<Com...@>=
integer i
real x
common/test/ x,i
@ Notice how the common block information is handled. You don't need to
include such stuff from a separate file.
@M NFMT #:0 /* This preprocessor command is a handy way of replacing numeric
statement labels by symbolic ones. Numeric statement labels will
never have to be used. */
@a
subroutine see
@<Com...@> /* You can abbreviate the name if it has already
appeared in full. */
write(6,NFMT) x,i
NFMT: format(' x = ',1pe10.2,', i = ',i2)
return
end
@ In fact, the Ratfor language is recommended for new Fortran codes. It's
best to do everything in Ratfor, but you can also work on a
module-by-module basis. Here's an example. Examine the listing of the
output file in Appendix~D to see how this is translated into standard
Fortran.
@a
@r/ @%* Set the language to Ratfor-77, for this section only. */
integer function f(a,b,n)
integer n;
real a(0:n-1),b(0:n-1);
{
integer k;
/* You can (and should) use a |do| loop for the following, but the |for|
construction is more flexible in general, so we use it to demonstrate. */
for(k=0; k<n; k++)
{
a(k) = k;
b(k) = k^2; /* In Ratfor and Fortran, you can use pretty
alternatives for archaic Fortran constructions such as~\.{.lt.} or~\.{**}. */
}
return n; // It's easy to return values from functions.
}
@* INDEX.